define(['helper/tools','translate','vocabularyBook'],function(tools,translate,vocabularyBook){
	var _this = null,
		$pageCont = $(".page_cont"),
		$wordCount = $(".word_count"),
		$transArea = $(".trans_area");
		
	var shi = 566666;
    var init = function(){
    	_this = this;
    	tools.router("pageReading");
    	
    };
    var dataTrans = {
    	
    	getChapterList: function(){
    		tools.ajax('reader/chapter_list',{book:tools.__UTILS.userActionRecord.current_bookId},
    			function(res){
    				tools.__UTILS.chapterList = res;  
    			} 		
    		)
    		// tools.__UTILS.chapterList = {"status":1,"chapter_licollectst":[{"chapter_name":"chapter11","start_page":1},{"chapter_name":"chapter22","start_page":5},{"chapter_name":"chapter11","start_page":10}]};
    	},
    	getPageData: function(){
    		tools.ajax('reader/get_data',
    			{
    				book:tools.__UTILS.userActionRecord.chooseBookId,
    				page_number:tools.__UTILS.userActionRecord.DefaultPageNumber
    			},
    			function(res){
    				if(res.status == 1){
    					tools.__UTILS.pageCont = res;
    					tools.__UTILS.userActionRecord.current_chapterName = res.chapter_name;
    					tools.__UTILS.userActionRecord.current_chapterId = res.chapter_id;
    					tools.__UTILS.userActionRecord.current_bookId = tools.__UTILS.userActionRecord.chooseBookId;
    					tools.__UTILS.userActionRecord.current_pageNumber = tools.__UTILS.userActionRecord.DefaultPageNumber;
    					tools.__UTILS.userActionRecord.current_bookName = tools.__UTILS.userActionRecord.chooseBookName;
    					tools.__UTILS.userActionRecord.getPageDataSuccess = 1;
    				}
    				else{
    					tools.__UTILS.userActionRecord.getPageDataSuccess = 0;
    					tools.tipZone("tip_wrong",tools.__UTILS.userActionRecord.chooseBookName+"的第 "+tools.__UTILS.userActionRecord.DefaultPageNumber+"页内容无法加载,请选择其他书或章节");
    					tools.__UTILS.userActionRecord.chooseBookId = tools.__UTILS.userActionRecord.current_bookId;
    					tools.__UTILS.userActionRecord.DefaultPageNumber = tools.__UTILS.userActionRecord.current_pageNumber;
    					tools.__UTILS.userActionRecord.chooseBookName = tools.__UTILS.userActionRecord.current_bookName;
    				}
    				
    			}
    		)
			// tools.__UTILS.pageCont = {"chapter_name":"Hahaha","data":"intellectual aesthetic as book to a category old books sword and a epic.\nBack to the two cultures (Commercial and Literary) and a I think a are beginning to merge. Publishers can no longer afford to rely purely on the literary category. e there certainly a longing for  a \n","article_words":{"aesthetic":1454,"book":30,"books":163,"category":438,"sword":11,"old":22},"article_words_size":94,"unknown_words_size":9,"unknown_words":{"aesthetic":1454,"book":30,"books":163,"category":438},"unknown_words_cn":{"aesthetic":"审美","book":"本书","category":"类别"},"keywords":{"aesthetic":1454,"book":30,"books":163,"category":438}};
   //  		tools.__UTILS.userActionRecord.current_bookId = tools.__UTILS.userActionRecord.chooseBookId;
			// tools.__UTILS.userActionRecord.current_pageNumber = tools.__UTILS.userActionRecord.DefaultPageNumber;
			// tools.__UTILS.userActionRecord.current_bookName = tools.__UTILS.userActionRecord.chooseBookName;
			// tools.__UTILS.userActionRecord.getPageDataSuccess = 1;
    	},
    	getAllPage:function(){

    		tools.ajax('reader/all_page',
    			{book:tools.__UTILS.userActionRecord.current_bookId},
	    		function(res){
	    			tools.__UTILS.userActionRecord.current_allPageNumber = res.all_page_num
	    		}
    		)
			// tools.__UTILS.userActionRecord.current_allPageNumber = 10;
    	},
    	getChapterWords:function(chapter_id){
    		tools.ajax('reader/chapter_red_word',
    			{
    				book_id:tools.__UTILS.userActionRecord.current_bookId,
    				chapter_id:chapter_id
    			},
    			function(res){
    				tools.__UTILS.chapterWords = res
    			}
    		)
			// tools.__UTILS.chapterWords = {"status":1,"unknown_words":{"affixed":771,"analysis":692,"blissfully":744,"chart":750,
			// "the":7,"existing":748,"extra":769,"fathom":738,"hopefully":765,"mechanic":757,"movements":751,
			// "surgeon":758,"themes":667,"those":371,"unaware":745,"underlying":740,"values":754}}
    	},
    	updateVocabularyByPage : function(){
			tools.ajax('user/update_vocabulary_by_page',{},
				function(res){
					tools.__UTILS.userActionRecord.current_vocabularySize = res.user_vocabulary_size;
				}
			);
			// tools.__UTILS.userActionRecord.current_vocabularySize += 10;
		},
		updateVocabularyByTrans : function(){
			tools.ajax('user/update_vocabulary',
				{
					type: tools.__UTILS.userActionRecord.transWordType,
					word: tools.__UTILS.userActionRecord.transWord,
					word_id: tools.__UTILS.userActionRecord.transWordId
				},
				function(res){
					tools.__UTILS.userActionRecord.current_vocabularySize = res.user_vocabulary_size;
				}
			);
			// tools.__UTILS.userActionRecord.current_vocabularySize = 60;
			
		},
    };
    var view = {
    	removeWordBgFade : function(){
    		$(".dot_word").removeClass("word_difficult word_easy");
    	},
    	catalogueInit : function(){
    		$(".catalogue_area").html("");
    		var chapter_list = tools.__UTILS.chapterList.chapter_list;
    		$.each(chapter_list,function(i){
    			$(".catalogue_area").append('<div class="catalogue_line" data-start_page_number="'+chapter_list[i].start_page+'" data-chapter_id="'+chapter_list[i].chapter_id+'">'+chapter_list[i].chapter_name+'</div>');
    		})
    	},
    	ellipsisShow : function(){
    		$(".catalogue_line,.book_tip,.chapter_tip").bind("mouseover",function(){
    			$(this).attr("title",$(this).html());

    		})
    	},
    	catalogueBookmarkWrapHide:function(){
    		$(".catalogue_bookmark_wrap").animate({left:"-230px"});
			tools.__UTILS.userActionRecord.catalogueBookmarkWrapShow = 0;
			tools.loading.hide();
    	},
    	dotWord : function(word_id,trans){
  
			$('[data-word_id="'+word_id+'"]').after('<span class="trans" data-trans_id='+word_id+'>'+trans+'</span><span class="dot" data-dot_id='+word_id+'></span>');
			$('[data-trans_id="'+word_id+'"]').each(function(){
				$(this).css({
					"width" : $(this).prev().width()*2,
					"left" : -0.5*($(this).parent().width())
				})
			});
			$("[data-dot_id="+word_id+"]").each(function(){
				$(this).css({
					"left":0.5*($(this).parent().width())
				})
			});
			
		},

		unDotWord : function(){
			$("[data-trans_id="+tools.__UTILS.userActionRecord.transWordId+"]").remove();
			$("[data-dot_id="+tools.__UTILS.userActionRecord.transWordId+"]").remove();
		},
		clickTransFade:function(){
			var $trans = $("[data-trans_id="+tools.__UTILS.userActionRecord.transWordId+"]");
			$trans.fadeIn(200,function(){
				setTimeout(function () {
					$trans.fadeOut(500);
				}, 500)
			});
		},
		clickTransFadeThenRemove:function(){
			var $trans = $("[data-trans_id="+tools.__UTILS.userActionRecord.transWordId+"]");
			$trans.fadeIn(200,function(){
				setTimeout(function () {
					$trans.fadeOut(500,function(){
						// setTimeout(function () {
							_this.view.unDotWord();
						// },500);
					});
				}, 500)
			});
		},
		clickDotHide: function(){
			$("[data-dot_id="+tools.__UTILS.userActionRecord.transWordId+"]").hide()
		},
		removeWordMouseLeaveEvent: function(){
			$('[data-word_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').unbind("mouseleave");
		},

    	formatAticle: function(){
    		var pageCont = tools.__UTILS.pageCont,article = pageCont.data;
                mark_cont = marked(pageCont.data),
                article = mark_cont.replace(/<p>/g,"<div class='p_a_r_a'>").replace(/<\/p>/g,"</div>").replace(/>([a-zA-Z])<br>/,'>$1').replace(/<br>/g,"</div><div class='p_a_r_a'>").replace(/(<h[1-6]*).*?(>.*?)(<\/h[1-6]*>)/g,'$1$2$3').replace(/<a.*?>(.*?)<\/a>/g,'$1');
    	        // if(/\n/.test(article)){
             //        article = "<div class='p_a_r_a'>" + pageCont.data.split("\n").join("</div><div class='p_a_r_a'>") + "</div>";
             //    }
             // console.log("mark化且替换过\n"+article); 
    		var replacedText = article;
            // console.log("mark前\n"+pageCont.data);
            // console.log("mark后\n"+mark_cont);
			$.each(pageCont.article_words,function(i){
				var word = i,
					word_id = pageCont.article_words[i],
					word_length = word.length;
					text = replacedText;
					reg = new RegExp(word,"gi");
				if($.inArray(word, ["div","span","data"]) < 0 && word.indexOf("<") < 0){
					replacedText = text.replace(reg,function(a,b){
						if((text[b-1]&&/[^a-zA-Z=_-]/.test(text[b-1])&&text[b+word_length]&&/[^a-zA-Z=_-]/.test(text[b+word_length])) || (!text[b-1]&&text[b+word_length]&&/[^a-zA-Z=_-]/.test(text[b+word_length])) || (!text[b+word_length]&&text[b-1]&&/[^a-zA-Z=_-]/.test(text[b-1])) || (!text[b-1]&&!text[b+word_length])){
						// if((text[b-1]&&/[^a-zA-Z<=>_-]/.test(text[b-1])&&text[b+word_length]&&/[^a-zA-Z<=>_-]/.test(text[b+word_length])) || (!text[b-1]&&text[b+word_length]&&/[^a-zA-Z<=>_-]/.test(text[b+word_length])) || (!text[b+word_length]&&text[b-1]&&/[^a-zA-Z<=>_-]/.test(text[b-1])) || (!text[b-1]&&!text[b+word_length])){
							return '<div class="word_area"><span class="dot_word" data-word_id='+word_id+'>'+a+'</span></div>';
						}
						else{
							return a;
						}
					});
				}
				
			});
			$.each(pageCont.keywords,function(i){				
				var word = i,
					text = replacedText;				
					word_length = word.length;
					word_id = pageCont.keywords[i],
					reg = new RegExp(word,"i");
				if($.inArray(word, ["div","span","data"]) < 0){
					replacedText = text.replace(reg,function(a,b){
						if((text[b-1]&&/[^a-zA-Z=_]/.test(text[b-1])&&text[b+word_length]&&/[^a-zA-Z=_]/.test(text[b+word_length])) || (!text[b-1]&&text[b+word_length]&&/[^a-zA-Z=_]/.test(text[b+word_length])) || (!text[b+word_length]&&text[b-1]&&/[^a-zA-Z=_]/.test(text[b-1])) || (!text[b-1]&&!text[b+word_length])){
						// if((text[b-1]&&/[^a-zA-Z=_-]/.test(text[b-1])&&text[b+word_length]&&/[^a-zA-Z=_-]/.test(text[b+word_length])) || (!text[b-1]&&text[b+word_length]&&/[^a-zA-Z=_-]/.test(text[b+word_length])) || (!text[b+word_length]&&text[b-1]&&/[^a-zA-Z=_-]/.test(text[b-1])) || (!text[b-1]&&!text[b+word_length])){
							return '<span class="key_word" data-key_word_id='+word_id+'>'+a+'</span>';
						}
						else{
							return a;
						}
					});
				}
				
				
			});
			$pageCont.html(replacedText);
			$.each(pageCont.unknown_words,function(i){				
				var word_id = pageCont.unknown_words[i],
				trans = pageCont.unknown_words_cn[i];
				_this.view.dotWord(word_id,trans);
				
			});

    	},

    	updatePageAndChapter: function(){
    		$(".current_page_num").html(tools.__UTILS.userActionRecord.current_pageNumber);
    		$(".chapter_tip").html(tools.__UTILS.pageCont.chapter_name)
    	},

    	allPageAndBookShow: function(){
    		$(".all_page_num").html(tools.__UTILS.userActionRecord.current_allPageNumber);
    		$(".book_tip").html(tools.__UTILS.userActionRecord.current_bookName);
    	},

    	wordArr: function(){
    		if(tools.__UTILS.userActionRecord.choose_easy == 0){
    			if(tools.__UTILS.pageCont.article_words[tools.__UTILS.userActionRecord.transWord]){
    				if(!tools.__UTILS.pageCont.unknown_words[tools.__UTILS.userActionRecord.transWord]){
    					tools.__UTILS.pageCont.unknown_words[tools.__UTILS.userActionRecord.transWord] = tools.__UTILS.userActionRecord.transWordId;
						tools.__UTILS.pageCont.unknown_words_cn[tools.__UTILS.userActionRecord.transWord] = tools.__UTILS.getTransRes.cn_trans;
    				}
    			}
    		}
    		else{
    			if(tools.__UTILS.pageCont.article_words[tools.__UTILS.userActionRecord.transWord]){
    				if(tools.__UTILS.pageCont.unknown_words[tools.__UTILS.userActionRecord.transWord]){
    					delete tools.__UTILS.pageCont.unknown_words[tools.__UTILS.userActionRecord.transWord];
						delete tools.__UTILS.pageCont.unknown_words_cn[tools.__UTILS.userActionRecord.transWord];
    				}
    			}
    		}
    	},

    	wordCount: function(){
    		$wordCount.html(tools.__UTILS.userActionRecord.current_vocabularySize)
    	},

    	centerPos: function(){
    		$(".center_wrapper").css({
    			left:0.5*$(document).width()-390,
    			height:$(document).height()
    		})
    		$(".center,.slide,.catalogue_bookmark_wrap").css({
    				height:$(document).height()
    		});
    		$(".chapter_words_area").css({
    			left:0.5*$(document).width()-400,
    			top:0.5*$(document).height()-305

    		})
    		$(window).resize(function(){
    			$(".center_wrapper").css({
    				left:0.5*$(document).width()-390,
    				height:$(document).height()
    			});
    			$(".center,.slide,.catalogue_bookmark_wrap").css({
    				height:$(document).height()
    			});
    			$(".chapter_words_area").css({
	    			left:0.5*$(document).width()-400,
	    			top:0.5*$(document).height()-305

	    		})
    		})
    	},
    	chapterWordsPartShowHide: function(){
    		$('[data-chapter_words_part="'+tools.__UTILS.userActionRecord.chapterWordsCurrentPart+'"]').show().siblings().hide();
    	},
    	chapterWordsRender: function(){
    		var chapter_words = tools.__UTILS.chapterWords.unknown_words,
    			count=0,part = 0;
    		$(".chapter_words_main_center").html("");
    		$.each(chapter_words,function(i){
    			count++;
    			var word_id = chapter_words[i];
    			if(count % 15 == 1 ){
    				part++;
    				$(".chapter_words_main_center").append('<div class="chapter_words_part" data-chapter_words_part="'+part+'"></div>');
    				$('[data-chapter_words_part="'+part+'"]').append('<span class="chapter_words_single chapter_words_difficult" data-chapter_words_word_id="'+word_id
    					+'">'+i+'</span>');
    			}
    			else{
    				$('[data-chapter_words_part="'+part+'"]').append('<span class="chapter_words_single chapter_words_difficult" data-chapter_words_word_id="'+word_id
    					+'">'+i+'</span>');
    			}

    		});
    		_this.regBtn.chapterWordsSingleClick();
    		tools.__UTILS.userActionRecord.chapterWordsAllPart = $(".chapter_words_part").length;
    		tools.__UTILS.userActionRecord.chapterWordsCurrentPart = 1;
    		_this.view.chapterWordsPartShowHide();
    		if(tools.__UTILS.userActionRecord.chapterWordsAllPart <= 1){
    			$(".chapter_words_turn_page").hide();
    		}
    		else{
    			$(".chapter_words_last_page").hide();
    		}
    	},
    	showCurrentChapterWords: function(){
			var option = {
                width:'100%',
                height:'100%',
                opacity:'0.7',
                zIndex:'5'
            };
            tools.loading.show(option);
			$(".chapter_words_area").show();
			// 在另一章节词时可能把翻页隐藏了，要先显示出来，在chapterWordsRender()再去判断哪个显示隐藏
			$(".chapter_words_turn_page").show();
            $(".chapter_words_next_chapter_btn").show();
			$(".chapter_words_chapter_name").html(tools.__UTILS.userActionRecord.current_chapterName)
			_this.dataTrans.getChapterWords(tools.__UTILS.userActionRecord.current_chapterId);
			_this.view.chapterWordsRender();
	


    	},
    	showNextChapterWords: function(){
    		var option = {
                width:'100%',
                height:'100%',
                opacity:'0.7',
                zIndex:'5'
            };
			tools.loading.show(option);
			$(".chapter_words_area").show();
			// 在另一章节词时可能把翻页隐藏了，要先显示出来，在chapterWordsRender()再去判断哪个显示隐藏
			$(".chapter_words_turn_page").show();
			$(".chapter_words_chapter_name").html(tools.__UTILS.userActionRecord.chapterWordsNextChapterName);
			$(".chapter_words_next_chapter_btn").hide();
			_this.dataTrans.getChapterWords(tools.__UTILS.userActionRecord.chapterWordsNextChapterId);
			_this.view.chapterWordsRender();
	
    	},
    	init: function(){ 		
    		_this.dataTrans.getPageData();
    		if(tools.__UTILS.userActionRecord.getPageDataSuccess == 1){ 
	    		_this.dataTrans.getChapterList();
	    		_this.dataTrans.getAllPage();
	    		_this.view.centerPos();
	    		_this.view.formatAticle();
	    		_this.view.allPageAndBookShow();
	    		_this.view.updatePageAndChapter();
	    		_this.view.catalogueInit();
	    		_this.view.ellipsisShow();
	    		_this.view.wordCount();
	    		_this.regBtn.catalogueBookmarkItem();
	    		_this.regBtn.dot(); 
	    	}  		
    	},

    	initByPage: function(){
    		_this.dataTrans.updateVocabularyByPage();
    		_this.dataTrans.getPageData();
    		if(tools.__UTILS.userActionRecord.getPageDataSuccess == 1){   		
				_this.view.formatAticle();
				_this.view.updatePageAndChapter();
				_this.view.wordCount();
				_this.regBtn.dot();
			}
    	},
    	initByTrans: function(){
    		// _this.view.wordArr();
    		_this.dataTrans.updateVocabularyByTrans();
    		_this.view.wordCount();
			
    	}
    	

    };
    var regBtn = {
    	init: function(){
    		$(".slide_bookshelf_btn").click(function(){
    			_this.view.removeWordBgFade()
    			// 点击书架按钮时，若目录书签已经侧滑出现，将之隐藏
    			if(tools.__UTILS.userActionRecord.catalogueBookmarkWrapShow == 1){
	    			_this.view.catalogueBookmarkWrapHide();
				}

    			require(['chooseBook'],function(chooseBook){
    				if(tools.__UTILS.bookList.length == 0){
    					chooseBook.init();
                        chooseBook.view.init();
    				}
    				else{
    					chooseBook.view.userWordSize();
    					tools.router("chooseBook");
    				}
    				
    			})
    		});
			$(".slide_catalogue_bookmark_btn").click(function(){
				if(tools.__UTILS.userActionRecord.catalogueBookmarkWrapShow == 0){
					$(".catalogue_bookmark_wrap").show();
                    $(".catalogue_bookmark_wrap").animate({left:"70px"});
					tools.__UTILS.userActionRecord.catalogueBookmarkWrapShow = 1;
					require(['helper/tools'],function(tools){
                        var option={opacity:'0.7'};
						tools.loading.show(option);
					});
					
					
				}
				else{
					_this.view.catalogueBookmarkWrapHide();

				}
			});
			
			$(".catalogue_btn").bind("click",function(){
				$(this).addClass("hover").siblings().removeClass("hover");
				$(".catalogue_area").fadeIn().siblings().hide();
				
			});
			$(".bookmark_btn").bind("click",function(){
				$(this).addClass("hover").siblings().removeClass("hover");
				$(".bookmark_area").fadeIn().siblings().hide();
				
			});
			var transFade = function(){
				$(".trans").fadeIn(300,function(){
					setTimeout(function () {
						$(".trans").fadeOut(500);
					}, 3000)
				});
			};
    		var lastPageAction = function () {
				event.stopPropagation;
				if(tools.__UTILS.userActionRecord.DefaultPageNumber >= 2 ){
					tools.__UTILS.userActionRecord.DefaultPageNumber--;
					_this.view.initByPage();
				}
			};
			$(".last_page").click(function () {
				lastPageAction();
			});
			var nextPageAction = function () {
				event.stopPropagation;
				if(tools.__UTILS.userActionRecord.DefaultPageNumber < tools.__UTILS.userActionRecord.current_allPageNumber){
					tools.__UTILS.userActionRecord.DefaultPageNumber++;
					var chapter_list = tools.__UTILS.chapterList.chapter_list;
					$.each(chapter_list,function(i){
						if(tools.__UTILS.userActionRecord.current_chapterId == chapter_list[i].chapter_id){
							if(tools.__UTILS.userActionRecord.DefaultPageNumber == chapter_list[i+1].start_page){
								tools.__UTILS.userActionRecord.chapterWordsNextChapterId = chapter_list[i+1].chapter_id;
								tools.__UTILS.userActionRecord.chapterWordsNextChapterName = chapter_list[i+1].chapter_name;
					            // 先把当前页的未标红的单词加入用户词汇量并显示词汇量
                                _this.dataTrans.updateVocabularyByPage();
                                _this.view.wordCount();
                               //显示当前章节难词 
								_this.view.showCurrentChapterWords();
								
							}
							else{
								_this.view.initByPage();
							}
							return false
						}
					})
				}
			};
			$(".next_page").click(function () {
				nextPageAction();
			});
			$("body").keydown(function (event) {
                if($("#pageReading").css("display") == "block"){
    				if(event.keyCode == 39 || event.keyCode==40) {
    					nextPageAction();
    				}
    				if(event.keyCode == 37 || event.keyCode == 38){
    					lastPageAction();
    				}
    				if(event.keyCode == 18){
    					transFade();
    				}
                }
			});
			$(".chapter_words_close").bind("click",function(){
				$(".chapter_words_area").hide();
				tools.loading.hide();
				_this.view.initByPage();
			});
			$(".chapter_words_last_page").bind("click",function(){
				if(tools.__UTILS.userActionRecord.chapterWordsCurrentPart >=2){
					$(".chapter_words_next_page").show();
					tools.__UTILS.userActionRecord.chapterWordsCurrentPart--;
					_this.view.chapterWordsPartShowHide();
					if(tools.__UTILS.userActionRecord.chapterWordsCurrentPart == 1){
						$(".chapter_words_last_page").hide();
					}
				}
			});
			$(".chapter_words_next_page").bind("click",function(){
				if(tools.__UTILS.userActionRecord.chapterWordsCurrentPart < tools.__UTILS.userActionRecord.chapterWordsAllPart){
					$(".chapter_words_last_page").show();
					tools.__UTILS.userActionRecord.chapterWordsCurrentPart++;
					_this.view.chapterWordsPartShowHide();
					if(tools.__UTILS.userActionRecord.chapterWordsCurrentPart == tools.__UTILS.userActionRecord.chapterWordsAllPart){
						$(".chapter_words_next_page").hide();
					}
				}
			});
			$(".chapter_words_next_chapter_btn").bind("click",function(){
				_this.view.showNextChapterWords();
			});
			$(".pagereading_desc_circle").bind("click",function(){
				$(".pageReading_option_tip_main").toggle(500);
			})
	    },
	    catalogueBookmarkItem: function(){
	    	$(".catalogue_line").bind("click",function(){
	    		if(/^\d+$/.test($(this).data("start_page_number"))){
					tools.__UTILS.userActionRecord.DefaultPageNumber = $(this).data("start_page_number");
					
					tools.__UTILS.userActionRecord.chapterWordsNextChapterId = $(this).data("chapter_id");
					tools.__UTILS.userActionRecord.chapterWordsNextChapterName = $(this).html();

					// _this.view.initByPage();
					// 点击某目录时，若目录书签侧滑块隐藏
					if(tools.__UTILS.userActionRecord.catalogueBookmarkWrapShow == 1){
		    			_this.view.catalogueBookmarkWrapHide();

					}
					_this.view.showNextChapterWords();
				}
				else{
					tools.tipZone("tip_wrong","该章节录入尚未就绪~")
				}
			});
	    },
	    dot: function(){
	    	$(".dot_word").bind("click",function(){
				event.stopPropagation();				 
				var	that = this;
				tools.__UTILS.appearance.word_pos = $(this).offset();
				tools.__UTILS.userActionRecord.transWordId = $(this).data("word_id");
				tools.__UTILS.userActionRecord.transWord = $(this).text().toLowerCase();
				tools.__UTILS.appearance.word_width = $(this).width();
				tools.__UTILS.appearance.word_height = $(this).height();
				if($('[data-trans_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').length){
					tools.__UTILS.userActionRecord.choose_easy = 1;
					tools.__UTILS.userActionRecord.transWordType = "add";
					$('[data-word_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').removeClass("word_difficult").addClass("word_easy");
				}
				else{
					tools.__UTILS.userActionRecord.choose_easy = 0;
					tools.__UTILS.userActionRecord.transWordType = "remove";
					$('[data-word_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').removeClass("word_easy").addClass("word_difficult")
				}
				translate.init();
				_this.view.initByTrans();
				if(tools.__UTILS.userActionRecord.choose_easy == 0){	
					// translate.regBtn.turnDifficulty();			
					_this.view.dotWord(tools.__UTILS.userActionRecord.transWordId,tools.__UTILS.getTransRes.cn_trans);
					_this.view.clickTransFade();
				}
				else{
					// translate.regBtn.turnEasy();
					// _this.view.unDotWord();
					_this.view.clickTransFadeThenRemove();
					_this.view.clickDotHide();
					
					
				}
				// $('[data-word_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').bind("mouseleave",function(){
				// 	console.log("离开单词"+tools.__UTILS.userActionRecord.enterTransArea);
				// 	setTimeout(function(){				
				// 		if(tools.__UTILS.userActionRecord.enterTransArea == 0){
				// 			$transArea.hide();
				// 			_this.view.removeWordMouseLeaveEvent();
						
				// 		}
				// 	},500)
			
				// })
			});
			var t;
			$(".dot_word").bind("mouseleave",function(){
				tools.__UTILS.userActionRecord.hoverPause = 0;
				tools.__UTILS.userActionRecord.enterTransArea = 0;
				clearTimeout(t);
				setTimeout(function(){
					if(tools.__UTILS.userActionRecord.enterTransArea == 0){
						$(".trans_area").hide();
					}
				},500)	

				
			});
			$(".dot_word").bind("mouseenter",function(){
	    		tools.__UTILS.userActionRecord.hoverPause = 1;
	    		event.stopPropagation();				 
				var	that = this;
	    		t = setTimeout(function(){
	    			if(tools.__UTILS.userActionRecord.hoverPause == 1){
				
						tools.__UTILS.appearance.word_pos = $(that).offset();
						tools.__UTILS.userActionRecord.transWordId = $(that).data("word_id");
						tools.__UTILS.userActionRecord.transWord = $(that).text().toLowerCase();
						tools.__UTILS.appearance.word_width = $(that).width();
						tools.__UTILS.appearance.word_height = $(that).height();
						
						translate.init();
						translate.view.init();
						
					}

	    		},2000)
			});
			
	
	    },
	    chapterWordsSingleClick: function(){
	    	$(".chapter_words_single").bind("click",function(){
    				event.stopPropagation();
    				tools.__UTILS.appearance.word_pos = $(this).offset();
					tools.__UTILS.userActionRecord.transWordId = $(this).data("chapter_words_word_id");
					tools.__UTILS.userActionRecord.transWord = $(this).text().toLowerCase();
					tools.__UTILS.appearance.word_width = $(this).width();
					tools.__UTILS.appearance.word_height = $(this).height();
					console.log(tools.__UTILS.appearance.word_pos);
					$(".chapter_words_status").css({
                        "left" : tools.__UTILS.appearance.word_pos.left + 0.5*tools.__UTILS.appearance.word_width,
                        "top" : tools.__UTILS.appearance.word_pos.top-20
                    });
                    if($(this).hasClass("chapter_words_difficult")){
                        $(this).addClass("chapter_words_easy").removeClass("chapter_words_difficult");
                        tools.__UTILS.userActionRecord.transWordType = "add";
                        $(".chapter_words_add_word").fadeIn(300,function(){
                            setTimeout(function() {
                                $(".chapter_words_add_word").fadeOut(300);
                            },500)
                        });
                    }
                    else{
                        $(this).addClass("chapter_words_difficult").removeClass("chapter_words_easy");
                        tools.__UTILS.userActionRecord.transWordType = "remove";
                        $(".chapter_words_remove_word").fadeIn(300,function(){
                            setTimeout(function() {
                                $(".chapter_words_remove_word").fadeOut(300);
                            },500)
                        });
                    }    
					_this.view.initByTrans();
    		})
	    }
    };
    return{
    	init: init,
    	regBtn: regBtn,
    	view: view,
    	dataTrans: dataTrans
    }
})